package com.sciai.controller;

import cn.com.sciai.aix.common.http.SciaiHttpResponseEntity;
import cn.com.sciai.aix.common.http.SciaiHttpResponseEntityBuilder;
import com.sciai.Service.SysLoginUserService;
import com.sciai.entity.req.LoginReq;
import com.sciai.entity.req.SysPersonUserReq;
import com.sciai.entity.vo.LoginUserInfo;
import com.sciai.utils.EmailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 登录注册
 * @author tqx
 * @version 1.0.0.0
 * <p>Title: SysLoginUserController </p >
 * <p>Description: 登录注册  </p >
 * Package: com.sciai.controller
 * Company: 沪渝研究院
 * Copyright: Copyright(c) AI+X
 * Date: 2023年04月102日 9:22
 */
@Slf4j
@RestController
@RequestMapping("/sysLoginUser")
public class SysLoginUserController {


    @Resource
    private SysLoginUserService sysLoginUserService;



    /**
      * 个人用户注册
      * @author tqx
      * @date 2023/6/6 9:29
      * Description: 个人用户注册
      * @param req
      * @return SciaiHttpResponseEntity
      */
    @PostMapping( "/personRegister")
    public SciaiHttpResponseEntity personRegister(@Valid @RequestBody SysPersonUserReq req) {
        try {
            return  sysLoginUserService.personRegister(req);
        }catch (Exception e){
            return SciaiHttpResponseEntityBuilder.builder().error("500",e.toString()).build();
        }
    }



    /**
     * 用户登录
     * @author tqx
     * @date 2023/6/6 11:30
     * Description: 用户登录
     * @param req
     * @return SciaiHttpResponseEntity<LoginUserInfo>
     */
    @ResponseBody
    @PostMapping(value = "/login")
    public SciaiHttpResponseEntity<LoginUserInfo> login(@RequestBody LoginReq req) {
        return sysLoginUserService.login(req);
    }

}
